
import { InjectionKey } from 'vue'
import { createStore, useStore as baseUseStore, Store } from 'vuex'
import { getUser } from '../api/dome'

export interface State {
  name: string,
  age:number
}

export const key: InjectionKey<Store<State>> = Symbol()

export const store = createStore<State>({
  state: {
    name: '默认名字',
    age:0
  },
  mutations: {
    GetUserInfo(state, date) { 
      console.log("触发mutations");
      
      state.name = date.name
      state.age = date.age
    }
  },
  actions: {
    getUserInfo({ commit }) { 
      let data = {
        name: '小智',
        age:18
      }
      console.log("触发actions");
      
      commit('GetUserInfo', data);
    }
  }
})

// 定义自己的 `useStore` 组合式函数
export function useStore() {
  return baseUseStore(key)
}